#########################################################################
# File Name: funcVersion.py
# Author: Wulei
# mail: wlinpisces@gmail.com
# Created Time: Sun 23 Feb 2014 06:00:03 PM
#########################################################################
#!/usr/bin/env python
#coding=utf-8

import os
import sys

def cdWalker(cdrom, cdcfile):
    export = " "
    for root, dirs, files in os.walk(cdrom):
        export += "\n %s;%s;%s" % (root, dirs, files)
    open(cdcfile,'w').write(export)

def cdcGrep(cdcpath, keyword):
    print cdcpath
    filelist = os.listdir(cdcpath)
    for cdc in filelist:
        if '.cdc' in cdc:
            print cdc
            cdcfile = open(cdcpath+'/'+cdc)
            for line in cdcfile.readlines():
                if keyword in line :
                    print line
        if os.path.isdir(cdc):
            cdcGrep(os.getcwd()+'/'+cdc, keyword)


if __name__ == '__main__':
    if  "-e" == sys.argv[1]:
        cdWalker('/home/wulei', sys.argv[2])
        print "record the imformation into %s" % sys.argv[2]
    else:
        print 'do again'
